<?php
require_once '../inc/config.php';
require_once '../inc/connexion.php';


// Copie dans le repertoire du script avec un nom
// incluant l'heure a la seconde pres 
//$repertoireDestination = dirname(__FILE__)."/images/";
//$nomDestination        = "fichier_.txt";

$ids = isset($_GET['ids']) ? $_GET['ids'] : "";


if (isset($_POST['envoyer'])) {
 
     if(isset($_POST['id']))      $id=$_POST['id'];
        else      $id="";
     if(isset($_POST['liste_contact_rs']))      $id_contact=$_POST['liste_contact_rs'];
        else      $id_contact="";
     if(isset($_POST['rdv_date']))      $rdv_date=$_POST['rdv_date'];
        else      $rdv_date="";
     if(isset($_POST['heure']))      $heure=$_POST['heure'];
        else      $heure="";
     if(isset($_POST['min']))      $min=$_POST['min'];
        else      $min="";
     if(isset($_POST['typ_rdv']))      $type_rdv=$_POST['typ_rdv'];
        else      $type_rdv="";
     if(isset($_POST['objet']))      $objet=$_POST['objet'];
        else      $objet="";
        if(isset($_POST['observations']))      $observations=$_POST['observations'];
        else      $observations="";
        $horaire = $heure.":".$min.":00";
      $sql = "UPDATE rendez_vous SET id_contact=$id_contact, rdv_date='$rdv_date', heure='$horaire', type_rdv='$type_rdv', objet='$objet', observations='$observations' WHERE id_contact=$ids";
      $envoi_requete = mysqli_query($connexion_serveur, $sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());;
 echo ' RENDEZ-VOUS MODIFIE ';     
}     
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title>MODIFIER UN renddez-vous</title>
        <link href="../bootstrap/css/bootstrap.css" type="text/css" rel="stylesheet">
        <link href="../css/style.css" type="text/css" rel="stylesheet">
 
    </head>
    <body>
    
        <?php  
        
        require_once "../inc/css_js_bootstrap/css_js_bootstrap.php"; 
        require_once '../inc/menus/menu_principal.php';
        ?>
        
        <br>
        <div id="div3">
        <input class="btn btn-default" type="button" value="Retour à la liste des rendez-vous" onclick="window.location.href='../rendez_vous/liste_rdv.php'">
        </div>
        <div id="div2" >
        <h2>Modifier un rendez-vous</h2><br>
        <?php
        $sql = "SELECT * FROM rendez_vous, contacts WHERE id_contact = '$ids'";
        $envoi_requete = mysqli_query($connexion_serveur, $sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());;
        $resultats = mysqli_fetch_array($envoi_requete); ?>
          </div>
        <div id="div1" >
        <form name="ajouter_contact" id="ajouter_contact" method="post" action="" enctype="multipart/form-data">
            <table>
            <tr>
                <td class="col1">Contact</td>
                <td class="col2"><select name="liste_contact_rs"> 
                        <?php 
                        //REQUETE SQL
                        $sql_ent2 = "SELECT * FROM entreprises, contacts, rendez_vous WHERE entreprises.id = contacts.id_entreprise AND contacts.id = rendez_vous.id_contact AND rendez_vous.id_contact = $ids";
                        $req_ent2 = mysqli_query($connexion_serveur, $sql_ent2);
                        while ($data_ent2 = mysqli_fetch_assoc($req_ent2)){
//                            if( $data_ent2["id_contact"] == $ids){
//                            echo '<option value="'.$data_ent2['id_contact'].'" > '.$data_ent2['nom'].' '.$data_ent2['prenom'].'  =>   '.$data_ent2['raison_sociale'].'</option>';
//                            }else {
                                ?><option value="<?php echo $data_ent2['id_contact']; ?>" selected> <?php echo $data_ent2['nom'];?>  <?php echo $data_ent2['prenom']; ?>   =>   <?php echo $data_ent2['raison_sociale']; ?></option><?php
//                            }
?>
                        <?php } ?>         
                        </select></td>
            </tr>
            <tr>
                 <td class="col1">Objet</td>
                 <td class="col2"><input type="text" name="objet" id="objet" maxlength="20" size="30" value='<?php echo $resultats['objet'];?>'></td>
            </tr>
            <tr>
                 <td class="col1">Date</td>
                 <td class="col2"><input type="date" name="rdv_date" id="rdv_date"  >&nbsp;&nbsp;<?php echo $resultats['rdv_date'];  ?></td>
            </tr>
            <tr>
                 <td class="col1">Heure</td>
                 <td class="col2"> <?php $heure = explode(":", $resultats['heure']);  ?>
                     <input type="text" name="heure" id="heure" maxlength="2" size="2" value='<?php echo $heure[0]; ?>'> : <input type="text" name="min" id="min" maxlength="2" size="2" value="<?php echo $heure[1];?>"></td>
            </tr>       
            <!--value="<?php // echo $resultats['rdv_date'];  ?>"-->
            <tr>
                 <td class="col1">Type de RDV</td>
                  <td class="col2"><select name="typ_rdv">
<!--                          <option style="text-decoration: underline;"><?php // echo $resultats['type_rdv'];  ?></option>-->
                            <option >Entretien</option>
                            <option >Vente</option>
                            <option >Client</option>
                            <option >Stage</option>
                            <option >Service</option>
                            <option >Ecole</option>
                      </select>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $resultats['type_rdv'];  ?></td>
            </tr>
            <tr>
                 <td class="col1">Observations</td>
                 <td class="col2"><?php echo $resultats['observations'];  ?></td>
            </tr>
            <tr>
                    <td class="col1"></td>
                    <td class="col2"><input type="submit" name="envoyer" value="Modifier"></td>
                </tr>
            </table>   
      <?php
        
        ?>
            <div style="margin-left:50% ;"><a href="../rendez_vous/suppr_rdv.php?id3=<?php echo $resultats['id_contact'];?>" style="color:#FF0000;" ><h4>Supprimer le contact</h4></a></div>
        </form>
         </div>
        
       
    </body>
</html>
